home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Very Newbie question on pointers
- Date: 6 Mar 1996 11:08:04 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4hjrmk$snr@sparcserver.lrz-muenchen.de>
- References: <bantolov-0603960018080001@bantolov.seanet.com>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- bantolov@bantolov.seanet.com (Bruce Antolovich) writes:
-
- >I hope that this is the right place to post such a question; if not, sorry
- >for the wasted bandspace.
-
- >I am very new to programming in C but have a large background in FORTRAN.
- >(please no snickers) I am having a problem with the memory location of
- >variables as described by pointers. I define several variables and try to
- >get their address in memory. Unfortunately, my code gives me the same
- >address for all variables! Any clues as to where I'm going wrong would be
- >very appreciated.
-
- >I don't think that it matters but I'm using Metrowerks CW on a PowerMac
- >6100/60.
-
- >Here is my sample code. (it does work correctly numerically)
-
- >#include <stdio.h>
-
- >/***********************/
- >/* Function Prototypes */
- >/***********************/
- >void SquareIt( int number, int *squarePtr, int *cubePtr );
-
- >int main (void)
- >{
-
- > int square;
- > int cube;
- > int *myCube;
- > int *mySquare;
- > double test;
- > mySquare = □
- > myCube = &cube;
- > printf("%d \n",&test);
-
- printf("%p \n", (void *) &test);
-
- "%p" expects a void pointer, "%d" expects an int. Rule 1 for working
- with pointers: Pointers are _not_ integers.
-
- This problem continues through the rest of your example.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-